package com.yundasys.lab10designpattern.observer;

/**
 * @PACKAGE_NAME: com.yundasys.lab10designpattern.observer
 * @NAME: HexaObserver
 * @USER: jiangta
 * @DATE: 2021/11/4
 * @TIME: 9:24 上午
 * @PROJECT_NAME: springboot-labs
 */
public class HexaObserver extends Observer {

    //在构造方法中订阅主题
    public HexaObserver(Subject subject) {
        this.subject = subject;
        this.subject.attach(this);
    }

    //该方法由主题类在数据变更的时候进行调用
    @Override
    public void update() {
        String result = Integer.toHexString(subject.getState()).toUpperCase();
        System.out.println("订阅的数据发生变化，新的数据处理为十六进制值为：" + result);
    }
}
